import { CHECC_API_BASE_DATA, CHECC_API_CMS } from '@/constants/proxy'
import request from '@/utils/request'
import { Pagination } from '@/components/Records/types'
import { ObjectType, ResponseDataPromise } from '../../typings/interfaces'
import * as proxy from '@/constants/proxy'


// 获取
export function getBdRoute(data:any,key:any) {
  return request({
    url: CHECC_API_BASE_DATA + '/bdRoute2/page',
    method: 'post',
    data:data,
    params:key
  })
}
// 路线新增
export function AddBdRoute(data:any,method:any) {
  return request({
    url: CHECC_API_BASE_DATA + '/bdRoute2',
    method:method,
    data:data,
  })
}

// 编辑查询
export function requestSingleData(id: any) {
  return request({
    url: CHECC_API_BASE_DATA + `/bdRoute2/${id}`,
    method: 'get',
  })
}
// 数据字典
export function dataDictionary(data: any) {
  return request({
    url: CHECC_API_CMS + '/dictItem/codelist',
    method: 'post',
    data
  })
}
// 所属省份
export function ProvinceQuery(data: any) {
  return request({
    url: CHECC_API_CMS + '/region/regionTree',
    method: 'post',
    data
  })
}

// 通过id查询
export function queryLineData(id: any){
  return request({
    url: CHECC_API_BASE_DATA + `/bdRoute2/${id}`,
    method:'GET',
  })
}
// 查询详情操作信息
export function queryByBusId(busId: any) {
  return request({
    url: CHECC_API_BASE_DATA + `/BpmHisInstance/queryByBusId/${busId}`,
    method: 'get',
  })
}


export const fetchRecordsRequest = (
  pagination: Omit<Pagination, 'total'>,
  data: ObjectType
): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bdRoute2/page',
    method: 'post',
    data,
    params: pagination,
  })

export const createRecordRequest = (data: ObjectType): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bdRoute2',
    method: 'post',
    data,
  })

export const editRecordRequest = (data: ObjectType): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bdRoute2',
    method: 'patch',
    data,
  })


export const deleteRecordsRequest = (ids: string[]) =>
  request({
    url: proxy.CHECC_API_BASE_DATA + `/bdRoute2`,
    method: 'delete',
    data: ids,
  })

export const lockRecordRequest = (id: string, dataLock: '0' | '1') =>
  request({
    url: proxy.CHECC_API_BASE_DATA + `/bdRoute2/lock/${id}?dataLock=${dataLock}`,
    method: 'post',
  })

export const exportRecordsRequest = (): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bdRoute2/export',
    method: 'post',
  })

export const importRecordsRequest = (): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bdRoute2/import',
    method: 'post',
  })

